package com.problem.leetcode;

/**
 * @author yanzhuoleo
 * @version V1.0
 * @Description: Problem24
 * @date 2018-01-05-下午7:59
 */

public class Problem24 {
    public static void main(String[] args) {

    }

    public ListNode swapPairs(ListNode head) {

        ListNode currentNode = head;
        while (currentNode != null && currentNode.next != null) {
            currentNode = swapPairs(currentNode, currentNode.next);
        }
        return head;
    }

    public ListNode swapPairs(ListNode node1, ListNode node2) {
        int value = 0;
        value = node1.val;
        node1.val = node2.val;
        node2.val = value;
        return node2.next;
    }

    public class ListNode {
        int                val;
        ListNode next;

        ListNode(int x) { val = x; }
    }

}
